package com.novax.ex.activity.provider.service;

import com.alibaba.fastjson.JSON;
import com.novax.ex.activity.infrastructure.entity.TaskLanguage;
import com.novax.ex.activity.infrastructure.entity.TaskTitle;
import com.novax.ex.activity.infrastructure.entity.TaskTitleLanguage;
import com.novax.ex.activity.infrastructure.mapper.TaskTitleMapper;
import com.novax.ex.common.base.BaseMapper;
import com.novax.ex.common.base.BaseService;
import com.novax.ex.common.constant.ActivityConstants;
import com.novax.ex.common.core.redis.RedisUtil;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.util.List;

@Service
public class TaskTitleService extends BaseService {

    @Resource
    private TaskTitleMapper taskTitleMapper;

    @Override
    protected BaseMapper getBaseMapper() {
        return taskTitleMapper;
    }


    /**
     * 根据语种信息查询任务标题
     *
     * @param language 语种
     * @return 任务标题
     */
    public List<TaskTitleLanguage> findTaskTitleByLanguage(String language) {

        // 增加缓存.
        String repeatKey = ActivityConstants.redisType.TASK_TITLE_LANGUAGE + language;
        Object taskTitleLanguageList = RedisUtil.get(repeatKey);
        if (null != taskTitleLanguageList) {
            return JSON.parseArray(taskTitleLanguageList.toString(), TaskTitleLanguage.class);
        }

        List<TaskTitleLanguage> taskTitleLanguages = taskTitleMapper.selectTaskTitleByLanguage(language);
        RedisUtil.set(repeatKey, JSON.toJSONString(taskTitleLanguages));
        return taskTitleLanguages;
    }

    /**
     * @param
     * @Description: 查询所有标题
     * @Author: ChenXi
     * @Date: 2023/6/25 10:52
     * @return: java.lang.Object
     **/
    public List<TaskTitle> queryAll() {
        return taskTitleMapper.queryAll();
    }

}
